/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	///  通知玩家连接逻辑服的参数
	/// module : gameServer
	/// </summary>
	public class ConnectLogicPOD : IPOD 
    {
        public readonly static Func<ConnectLogicPOD> FACTORY = () => new ConnectLogicPOD();
		public static Func<ConnectLogicPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        /// 
        /// </summary>
		public string token;
		/// <summary>
        /// 
        /// </summary>
		public string logicServerId;
		/// <summary>
        /// 
        /// </summary>
		public string gameServerId;
		/// <summary>
        /// 
        /// </summary>
		public string host;
		/// <summary>
        /// 
        /// </summary>
		public int port;
		/// <summary>
        ///  连接逻辑服的缘由，主要用于客户端连接前展示
        /// </summary>
		public ConnectLogicReason reason;
		/// <summary>
        ///  关联的关卡配置id，可能需要展示
        /// </summary>
		public int levelCid;
		
		
		
		/*-- constructors --*/
		public ConnectLogicPOD() {}
		public ConnectLogicPOD(string token, string logicServerId, string gameServerId, string host, int port, ConnectLogicReason reason, int levelCid) {
			this.token = token;
			this.logicServerId = logicServerId;
			this.gameServerId = gameServerId;
			this.host = host;
			this.port = port;
			this.reason = reason;
			this.levelCid = levelCid;
		}
		  public void Serial(SOutputStream _out) {
                if(token != default) {
                    _out.WriteByte(1);
                    _out.Write_string(token);
                }
                if(logicServerId != default) {
                    _out.WriteByte(2);
                    _out.Write_string(logicServerId);
                }
                if(gameServerId != default) {
                    _out.WriteByte(3);
                    _out.Write_string(gameServerId);
                }
                if(host != default) {
                    _out.WriteByte(4);
                    _out.Write_string(host);
                }
                if(port != default) {
                    _out.WriteByte(5);
                    _out.Write_int(port);
                }
                if(reason != default) {
                    _out.WriteByte(6);
                    _out.Write_byte((sbyte)reason);
                }
                if(levelCid != default) {
                    _out.WriteByte(7);
                    _out.Write_int(levelCid);
                }
        }
            
        public void UnSerial(SInputStream _in) {
            while (_in.HasRemaining())
            {
                int _key = _in.ReadByte();
                switch (_key)
                {
                    case 1:
                        token = _in.Read_string();
                        break;
                    case 2:
                        logicServerId = _in.Read_string();
                        break;
                    case 3:
                        gameServerId = _in.Read_string();
                        break;
                    case 4:
                        host = _in.Read_string();
                        break;
                    case 5:
                        port = _in.Read_int();
                        break;
                    case 6:
                        reason = (ConnectLogicReason)_in.Read_byte();
                        break;
                    case 7:
                        levelCid = _in.Read_int();
                        break;
                    default: _in.SkipBinary();break;
                }
            }
        }
		
		public ConnectLogicPOD Clone() {
            ConnectLogicPOD o = DynamicFactory();
            o.token = token;
            o.logicServerId = logicServerId;
            o.gameServerId = gameServerId;
            o.host = host;
            o.port = port;
            o.reason = reason;
            o.levelCid = levelCid;
            return o;
        }
        
        public void Clear() {
            token = default;
            logicServerId = default;
            gameServerId = default;
            host = default;
            port = default;
            reason = default;
            levelCid = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "ConnectLogicPOD [";
			str += "token=";
			str += token;
			str += ", logicServerId=";
			str += logicServerId;
			str += ", gameServerId=";
			str += gameServerId;
			str += ", host=";
			str += host;
			str += ", port=";
			str += port;
			str += ", reason=";
			str += reason;
			str += ", levelCid=";
			str += levelCid;
			str += "]";
			return str;
		}
		
	}
}